﻿using BarcodeDelay.business;
using BarcodeDelay.utility;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BarcodeDelay.view
{
    public partial class FrmPos : Form
    {
        public FrmPos()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                
                this.Close();
                //this.login(user, pwd);

            }
            catch(Exception ex)
            {

            }
        }
        private void login(string user,string pwd)
        {
            try
            {
                string md5Pwd = Utility.GenerateMD5(pwd);
                JObject jObj = new JObject();
                jObj["account"] = user;
                jObj["password"] = md5Pwd;
                jObj["captchaToken"] = "";
                jObj["countryId"] = "1";
                jObj["randstr"] = "@JI3";
                jObj["ticket"] = "t0388LE9JJfJ898TJoWTrUcYOn4p9i88r0ZUqkmnMiDluytJOFWDr95m4RBY7pFJ7Bsv5X8sHaoRapGBxnbqITpQVJtkjxuGlPWXrXrb5doL_lvtznbVGybBQ**";
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string strUrl = "https://jmsgw.jtexpress.com.cn/basicdata/login";
                //string postData = "{\"account\":\"0025955601\",\"password\":\"04c8e8914de0ee4ebe5221f6a669484d\",\"captchaToken\":\"\",\"countryId\":\"1\"}";
                string res = HttpClient.HttpUtil.Instance.GetPage(strUrl, postData);
                JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                JToken status = (JToken)jsonObj["code"];
                if(status!=null&& status.ToString()=="1")
                {
                    JObject jsonObjData = (JObject)jsonObj["data"];
                    if(jsonObjData!=null)
                    {
                        JToken token = (JToken)jsonObjData["captchaToken"];
                        MemberInfo.Instance.token = token.ToString();
                        this.Close();
                    }
                }
                else
                {
                    JToken msg = (JToken)jsonObj["msg"];
                    MessageBox.Show("登录失败"+ msg.ToString());
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show("登录失败" + ex.ToString());
            }
            
            

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmLogin_Load(object sender, EventArgs e)
        {
            
        }
    }
}
